<?php
/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * User Application Models: Members / Users
 * Started: September 2, 2009 12:07 PM
 * Script version: 1.0
 */
class users{
	public function create($username, $password, $email, $dname = NULL, $groupid = NULL){
		global $db, $config, $main;
		$username = mysql_real_escape_string(stripslashes($username));
		if($dname == NULL){
			$dname = $username;
		}
		$email = mysql_real_escape_string(stripslashes($email));
		$password = $main->makePassword(stripslashes($password));
		// FIXME: GroupID Implementation?
		$query = $db->query("INSERT INTO `".$config["db"]["prefix"]."users`(`id`,`username`,`display`,`password`,`email`,`group`)VALUES(NULL, '{$username}', '{$dname}', '{$password}', '{$email}', 4);");
		return $query;
	}
	
	public function select_all(){
		global $db;
		$this->queryAll = $db->select("users", "*", 0, "ORDER BY `joined` DESC");
		return $this->queryAll;
	}
	
	public function select_latest(){
		global $db;
		if(!isset($this->queryAll)) $this->select_all();
		if(!isset($this->latestArray)){
			while($array = $db->fetch_array($this->queryAll) and !isset($i)){
				$i = 1;
				$this->latestArray = $array;
			}
		}
		// Now yeah
		return $this->latestArray;
	}
}
